function getVariableFromGTAPFile(inFileName, outFileName, variableName)

infile=fopen(inFileName,'r');
tline = fgets(infile);

outfile=fopen(outFileName,'w');

bRecord=0; % whether we should record
bStop=0;
lineNo=1;
while (bStop==0) && (ischar(tline))
    if bRecord==0
        if strcmp(tline(1:min(8,end)),'!Header:') && ~isempty(regexpi(tline,['!Header: ' variableName],'match'))
            % we've found the starting line
            % go to the next line
            tline = fgets(infile);
            tline=regexprep(tline,'Value',variableName);
            fprintf(outfile,'%s',tline);
            %start recording
            bRecord=1;
        end
    else
        if ~isempty(regexpi(tline,'!Header:','match'))
            % we need to stop recording, end of entry
            bRecord=0;
            bStop=1;
        else
            % record
            fprintf(outfile,'%s',tline);
        end
    end
    tline = fgets(infile);
    lineNo=lineNo+1;
    if mod(lineNo,5000)==0
        fprintf('%i\n',lineNo);
    end
end
fclose(infile);
fclose(outfile);
end